/**
 * <p>
 * </p>
 *
 * @author zhuolin
 * @since 2020/5/27
 */
public class SimpleWaitAndNotify {

    final static Object o = new Object();

    public static class T1 extends Thread {
        @Override
        public void run() {
            synchronized (o) {
                System.out.println(System.currentTimeMillis() + " T1 start");
                try {
                    System.out.println(System.currentTimeMillis() + " T1 wait");
                    o.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(System.currentTimeMillis() + " T1 end");
            }

        }
    }

    public static class T2 extends Thread {
        @Override
        public void run() {
            synchronized (o) {
                try {
                    Thread.sleep(100L);
                    System.out.println(System.currentTimeMillis() + " T2 start");
                    System.out.println(System.currentTimeMillis() + " T2 notify");
                    o.notify();
                    System.out.println(System.currentTimeMillis() + " T2 end");
                    Thread.sleep(200L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }

        public static void main(String[] args) {
            Thread t1 = new T1();
            Thread t2 = new T2();
            t1.start();
            t2.start();
        }
    }
}
